package com.apes.fn.server.fnCompany.service;

import com.apes.fn.server.fnCompany.model.FnCompanyScope;
import com.apes.fn.server.fnCompany.repository.FnCompanyScopeServiceRepository;
import com.apes.framework.api.DomainService;
import com.apes.framework.jpa.spec.JpaDsl;
import com.apes.scm.masterdata.frame.model.Dept;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * Creator: zouyc
 * CreateDate: 2020-03-30 13:51
 * Description:
 **/
@Service("fnCompanyScopeService")
public class FnCompanyScopeService extends DomainService {
    @Autowired
    FnCompanyScopeServiceRepository fnCompanyScopeServiceRepository;

    @Value("${apes.switched:false}")
    private Boolean switched;

    public boolean isToOldFrameDept(Dept dept){
        List<FnCompanyScope> fnCompanyScopes =
                fnCompanyScopeServiceRepository.findAll(JpaDsl.toCriteriaByEq("company.id",dept.getCompany().getId()));
        if(fnCompanyScopes.size() == 0||switched) return false;
        return true;
    }
}
